﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HREDU.Hoang_Tuan;
using HREDU.Hoang_Tuan.Classes;
using Microsoft.Win32;

namespace HREDU
{
    public partial class frmMain : Form
    {
        const string PH_NV = "NHANVIEN";
        public frmMain()
        {
            InitializeComponent();
        }

        public void ChangeSystemDateTimeFormat()
        {
            RegistryKey reg;
            reg = Registry.Users.OpenSubKey("S-1-5-21-1757981266-861567501-682003330-500\\Control Panel\\International", true);
            if (System.Convert.ToString(reg).Trim() == string.Empty)
                MessageBox.Show("Blank");
            else
            {
                reg.SetValue("sShortDate", "dd/MM/yyyy");
                reg.SetValue("sLongDate", "dd/MM/yyyy");
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            SetEnableSomeMenus(false);
            frmLogin frm = new frmLogin();
            frm.ShowDialog();
            if (frm.LoginOK)
            {
                if (CUsers.isAdmin(MITI.BaseDB.Instance.g_UserName))
                {
                   SetEnableSomeMenus(true);
                }
                danhSáchCánBộCôngChứcToolStripMenuItem_Click(null, null);
            }
        }

        private void SetEnableSomeMenus(bool val)
        {
            for (int i = 0; i <= menuStrip1.Items.Count - 2; i++)
            {
                ToolStripMenuItem menu = (ToolStripMenuItem)menuStrip1.Items[i];
                for (int j = 0; j <= menu.DropDownItems.Count - 1; j++)
                {
                    try
                    {
                        ToolStripMenuItem m = (ToolStripMenuItem)menu.DropDownItems[j];
                        m.Enabled = val;
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            đăngNhậpToolStripMenuItem.Enabled = !val;
            thoátToolStripMenuItem.Enabled = true;
        }

        private void danhSáchNângLươngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDSNangLuong frm;
            frm = new frmDSNangLuong();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
        }

        private void danhSáchCánBộCôngChứcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDSNHANSU frm;
            frm = new frmDSNHANSU();
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
        }

        private void quảnLýDanhMụcToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDanhMuc frm;
            frm = new frmDanhMuc();
            frm.ShowDialog();
        }

        private void quảnLýĐơnVịToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDONVI frm;
            frm = new frmDONVI(enumNHOM.DONVI);
            frm.ShowDialog();
        }

        private void quảnLýChứcVụToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDONVI frm;
            frm = new frmDONVI(enumNHOM.CHUCVU);
            frm.ShowDialog();
        }

        private void quảnLýNgạchBậcLươngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmBangLuong frm;
            frm = new frmBangLuong();
            frm.ShowDialog();
        }

        //private void mnQuanlyNV_Click(object sender, EventArgs e)
        //{
        //    /*
        //     * Dungnv : 09/09/2009
        //     * View form quan ly SearchCommon
        //     */
        //    frmSearchCommon objSearchCommom = new frmSearchCommon();
        //    objSearchCommom.strGroup = PH_NV;
        //    objSearchCommom.Show();

 
        //}

        private void đăngNhậpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMain_Load(null, null);
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
                {
                    frm.Close();
                }
                //dang xuat
                SetEnableSomeMenus(false);
                đăngNhậpToolStripMenuItem.Enabled = true;
        }

        private void CascadeWindowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }

        private void ArrangeWindowsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void TitleVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileVertical);
        }

        private void TitleHorizonToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void chọnKếtNốiToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void quảnLýMenuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!CUsers.isAdmin(MITI.BaseDB.Instance.g_UserName))
            {
                MessageBox.Show("Bạn không có quyền thực hiện chức năng này.");
                return;
            }
            frmChonMenu frm = new frmChonMenu(this);
            frm.Show();
        }

        private void saoLưuDữLiệuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmBackup frm = new frmBackup(true);
            frm.ShowDialog();
        }

        private void quảnLýNgườiDùngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.ProcessStartInfo startInfo;
            System.Diagnostics.Process pStart = new System.Diagnostics.Process();
            startInfo = new System.Diagnostics.ProcessStartInfo(Application.StartupPath + "\\Quan ly nguoi dung.exe");
            pStart.StartInfo = startInfo;
            pStart.Start();
        }

        private void danhMụcĐịaDanhToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDIADANH frm = new frmDIADANH();
            frm.ShowDialog();
        }

        private void đổiMậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDoiMatKhau frm = new frmDoiMatKhau();
            frm.ShowDialog();
        }

        private void cậpNhậtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCapNhatPhanMem frm = new frmCapNhatPhanMem();
            frm.ShowDialog();
        }

        private void danhMụcToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmConvertDanhMuc frm = new frmConvertDanhMuc();
            frm.ShowDialog();
        }
    }
}